package core

import (
	"fmt"

	"server/global"
	"server/initialize"
	"server/service/system"
	"go.uber.org/zap"
)

type server interface {
	ListenAndServe() error
}

func RunWindowsServer() {
	if global.GVA_CONFIG.System.UseMultipoint || global.GVA_CONFIG.System.UseRedis {
		// 初始化redis服务
		initialize.Redis()
		initialize.RedisList()
	}

	if global.GVA_CONFIG.System.UseMongo {
		err := initialize.Mongo.Initialization()
		if err != nil {
			zap.L().Error(fmt.Sprintf("%+v", err))
		}
	}
	// 从db加载jwt数据
	if global.GVA_DB != nil {
		system.LoadAll()
	}

	Router := initialize.Routers()

	address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr)
	s := initServer(address, Router)

	global.GVA_LOG.Info("server run success on ", zap.String("address", address))

	
	global.GVA_LOG.Error(s.ListenAndServe().Error())

	// router := Router
	// router.Delims("{[{", "}]}")
	// router.SetFuncMap(template.FuncMap{
	// 	"formatAsDate": formatAsDate,
	// })
	// router.LoadHTMLFiles("../template/testdata/raw.tmpl")

	// router.GET("/raw", func(c *gin.Context) {
	// 	c.HTML(http.StatusOK, "raw.tmpl", gin.H{
	// 		"now": time.Date(2017, 0o7, 0o1, 0, 0, 0, 0, time.UTC),
	// 	})
	// })

	// router.Run(":8080")
}

// func formatAsDate(t time.Time) string {
// 	year, month, day := t.Date()
// 	return fmt.Sprintf("%d%02d/%02d", year, month, day)
// }
